//
//  TMDiscountDetailView.m
//  国学商家管理
//
//  Created by Tao Li on 2018/7/6.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMDiscountDetailView.h"
#import "TMMyDiscountViewController.h"
@interface TMDiscountDetailView()<UIScrollViewDelegate>
@property (nonatomic, strong) TMMyDiscountViewController *vc;
@property (nonatomic, strong) TMMyDiscountViewController *vc1;

@end
@implementation TMDiscountDetailView

-(void)awakeFromNib{
    [super awakeFromNib];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.contentSC setContentSize:CGSizeMake(kWindowW*2, 0)];
    self.contentSC.pagingEnabled = YES;
    self.contentSC.delegate = self;
    self.vc = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil] instantiateViewControllerWithIdentifier:@"TMMyDiscountViewController"];
    self.vc1 = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil] instantiateViewControllerWithIdentifier:@"TMMyDiscountViewController"];
    [self.contentSC addSubview:self.vc.view];
    [self.contentSC addSubview:self.vc1.view];
    self.vc.view.frame = CGRectMake(0, 0, self.contentSC.bounds.size.width, self.contentSC.bounds.size.height);
    self.vc1.view.frame = CGRectMake(kWindowW, 0, self.contentSC.bounds.size.width, self.contentSC.bounds.size.height);
    [self begainStates];
}
- (void)begainStates{
    for (UIButton *btn in self.canUseBtns) {
        if (btn.tag == 10) {
            btn.selected = YES;
            [btn setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#05B48D"] forState:UIControlStateSelected];
            self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
            self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
        }else{
            //           self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
            //            self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
        }
    }
}
- (IBAction)closeBtnClick:(UIButton *)sender {
    [self removeFromSuperview];
}
- (IBAction)buttonActions:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected == NO) {
        [sender setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#999999"] forState:UIControlStateNormal];
    }else{
        [sender setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#05B48D"] forState:UIControlStateSelected];
    }
    for (int i= 0 ;i < self.canUseBtns.count ; i++) {
        if (sender.tag == 10 + i ) {
            sender.selected = YES;
            continue;
        }
        UIButton *btn = [self viewWithTag:10 + i];
        btn.selected = NO;
    }
    if (sender.tag == 10) {
        [self.contentSC setContentOffset:CGPointMake(0,0) animated:YES];
        self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
        self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
    }else{
         [self.contentSC setContentOffset:CGPointMake(kWindowW,0) animated:YES];
        self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
         self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
    }
}
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    if (isUser == YES) {
//        if (scrollView.contentOffset.x >kWindowW) {
//            [self.contentSC setContentOffset:CGPointMake(kWindowW,0) animated:YES];
//        }else{
//            [self.contentSC setContentOffset:CGPointMake(0,0) animated:YES];
//        }
//        isUser = NO;
//    }
//}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int  index = scrollView.contentOffset.x/kWindowW;
    //[self.contentSC setContentOffset:CGPointMake(kWindowW*index,0) animated:YES];
    UIButton *btns = [self viewWithTag: 10];
    UIButton *btns2 = [self viewWithTag: 20];
    if (index == 0) {
        btns.selected = YES;
        btns2.selected = NO;
        [self buttonActions:btns];
//        [btns setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#05B48D"] forState:UIControlStateNormal];
//        self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
//        self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
//        [btns2 setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#999999"] forState:UIControlStateNormal];
    }else{
        btns2.selected = YES;
        btns.selected = NO;
        [self buttonActions:btns2];
//        [btns2 setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#05B48D"] forState:UIControlStateNormal];
//        self.unUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
//        self.canUseView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#FFFFFF"];
//        [btns setTitleColor:[UIColor hx_colorWithHexRGBAString:@"#999999"] forState:UIControlStateNormal];
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}
@end
